package com.pivotal.cloud.crypto.keygen;

import java.security.SecureRandom;

/**
 * @className: com.pivotal.cloud.security.crypto.keygen.SecureRandomBytesKeyGenerator
 * @projectName: PivotalCloud项目
 * @module: PivotalCloud项目-SecureRandomBytesKeyGenerator类，主要位于Security安全模块-安全随机数Key生成器模块
 * @content: SecureRandomBytesKeyGenerator-安全随机数Key生成器
 * @author: Powered by Marklin
 * @datetime: 2025-06-24 15:11
 * @version: 1.0.0
 * @copyright: Copyright © 2018-2025 PivotalCloud Systems Incorporated. All rights
 * reserved.
 */
public class SecureRandomBytesKeyGenerator implements BytesKeyGenerator {

	private static final int DEFAULT_KEY_LENGTH = 8;

	private final SecureRandom random;

	private final int keyLength;

	SecureRandomBytesKeyGenerator() {
		this(8);
	}

	SecureRandomBytesKeyGenerator(int keyLength) {
		this.random = new SecureRandom();
		this.keyLength = keyLength;
	}

	@Override
	public int getKeyLength() {
		return this.keyLength;
	}

	@Override
	public byte[] generateKey() {
		byte[] bytes = new byte[this.keyLength];
		this.random.nextBytes(bytes);
		return bytes;
	}

}
